﻿//********************************************************************
// 
//  file:  frmMetaData.cs
// 
//  (C) Copyright 2010, Diomede Corporation
//  All rights reserved
// 
//  Use, modification, and distribution is subject to   
//  the New BSD License (See accompanying file license.txt).
// 
//********************************************************************

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Diomede.SDK;

namespace Diomede.Explorer
{
    public partial class frmMetaData : Form
    {
        public frmMetaData()
        {
            InitializeComponent();
        }

        public frmMetaData(ISession session)
        {
            InitializeComponent();
            Session = session;
        }

        public ISession Session { get; set; }

        public int SelectedMetaDataID { get; set; }

        public long? FileID { get; set; }

        private void frmMetaData_Load(object sender, EventArgs e)
        {
            this.Icon = Diomede.Explorer.Properties.Resources.props;
            IFileManagement f = Session as IFileManagement;
            if (FileID.HasValue)
            {
                grid.DataSource = f.StoredFileInstance(FileID.Value).MetaData;
            }
            else
            {
                IGetMetaDataExecResult result = f.GetMetaData(null, string.Empty, string.Empty);
                if (result.Status != Diomede.SDK.Enums.ExecutionResults.Success)
                {
                    MessageBox.Show(this, result.Message, "Error");
                    return;
                }
                grid.DataSource = result.MetaData;
            }

            grid.Columns["Session"].Visible = false;
            grid.Columns["ExtensionData"].Visible = false;
            
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            // check to make sure some rows are selected first...
            if (grid.SelectedRows.Count > 0)
            {
                SelectedMetaDataID = (int)grid.SelectedRows[0].Cells["MetaDataID"].Value;
            }
            DialogResult = DialogResult.OK;
            Close();
        }
    }
}
